package com.arch.dev.client.view;


import com.arch.dev.client.controller.BudgetController;
import com.arch.dev.client.vo.CatagoryVO;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Widget;

public class CatagoryDialogView extends DialogBox {

	private static CatagoryDialogViewUiBinder uiBinder = GWT
			.create(CatagoryDialogViewUiBinder.class);

	interface CatagoryDialogViewUiBinder extends
			UiBinder<Widget, CatagoryDialogView> {
	}


	
	@UiField
	public CatagoryFormView formView;

	Widget widget;

	public CatagoryDialogView(String firstName, final Widget widget) {
		super(false,true);
		this.widget = widget;
		Widget w = uiBinder.createAndBindUi(this);
		setText("Add Details");
		setSize("100%", "100%");
		setGlassEnabled(true);
		//setAnimationEnabled(true);		
		setWidget(w);		
		
		formView.saveButtonAddClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				BudgetController.getInstance().persistCatagoryValues(widget,
					formView.populateVo());
				hide();
			}
		});

		formView.getCancelButton().addClickHandler(new ClickHandler() {
			
			public void onClick(ClickEvent event) {
				hide();
				
			}
		});
		

	}

	public void populateFields(CatagoryVO catagoryVO) {

		formView.populateFields(catagoryVO);

	}


	
	public void show()

	{
		int ph = getOffsetHeight();

		int pw = getOffsetWidth();

		int wh = Window.getClientHeight();

		int ww = Window.getClientWidth();

		int locx = (ww - pw - getOffsetWidth()) / 3;

		int locy = (wh - ph - getOffsetHeight()) / 3;

		super.setPopupPosition(locx, locy);

		super.show();

	}
}
